/**
 * Columns.java
 *
 * Copyright (c) 2009 prjmanager All Rights Reserved.
 *
 * This source file may not be copied, modified or redistributed,
 * in whole or in part, in any form or for any reason, without the express
 * written consent of prjmanager .
 **/

package ro.prjmanager.model;


import javax.persistence.*;

/**
 * This class from the domain model is mapping the table columns
 *
 * @author Viorel Tacliciu
 * @version 0.0.1
 */

@Table(name = "COLUMNS")
@Entity
public class Columns {

    //define attributes that maps all columns of the coresponding table
    //this attribute maps the column PRIMARY_KEY
    private java.lang.Integer primaryKey;
    //this attribute maps the primary key column ID
    private java.lang.Integer id;
    //this attribute maps an bidirectional association
    //it means that FOREIGN_COLUMN from table columns is a foreign key to ID

    //this attribute maps an bidirectional association
    //it means that RELATION_COLUMNS from table columns is a foreign key to ID
    private java.util.List<Columns> relationColumns;
    //this attribute maps the column DATABASE_COLUMN_NAME
    private java.lang.String databaseColumnName;
    //this attribute maps the column JAVA_COLUMN_NAME
    private java.lang.String javaColumnName;
    //this attribute maps the column JAVA_TYPE
    private java.lang.String javaType;
    //this attribute maps the column DATABASE_TYPE
    private java.lang.String databaseType;
    //this attribute maps the column ORDER_COL
    private java.lang.Integer orderCol;
    //this attribute maps the column FOREIGN_KEY
    private java.lang.Integer foreignKey;
    //this attribute maps the column NULLABLE
    private java.lang.Integer nullable;
    //this attribute maps the foreign key column FOREIGN_COLUMN
    private Columns foreignColumn;
    //this attribute maps the column COL_SIZE
    private java.lang.Integer colSize;
    //this attribute maps the foreign key column RELATION_COLUMNS

    //this attribute maps the foreign key column OWNER_TABLE
    private Models ownerTable;
    //this attribute maps the foreign key column FK_FOREIGN_MODEL
    private ForeignModel fkForeignModel;
    //end mapping columns

    //define getters and setters with coresponding ejb3 annotation, depending of the type
    //of the relation for the column

    /**
     * This method gets the primaryKey attribute
     *
     * @return - an  java.lang.Integer  object
     */
    @Column(name = "PRIMARY_KEY")
    public java.lang.Integer getPrimaryKey() {
        return this.primaryKey;
    }

    /**
     * The setter for PRIMARY_KEY column
     *
     * @param primaryKey -  an  java.lang.Integer  object
     */
    public void setPrimaryKey(java.lang.Integer primaryKey) {
        this.primaryKey = primaryKey;
    }

    /**
     * Mapping the primary key
     *
     * @return - java.lang.Integer the primary key for this entity
     */
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @Column(name = "ID")
    public java.lang.Integer getId() {
        return this.id;
    }

    /**
     * The setter for ID column
     *
     * @param id -  an java.lang.Integer object
     */
    public void setId(java.lang.Integer id) {
        this.id = id;
    }

    /**
     * This method maps an OneToMany relation between this table and
     * Columns table
     *
     * @return - an list of Columns objects
     */
    @OneToMany(cascade = CascadeType.ALL)
    @JoinColumn(name = "RELATION_COLUMNS", referencedColumnName = "ID")
    public java.util.List<Columns> getRelationColumns() {
        return this.relationColumns;
    }

    /**
     * This method sets the field relationColumns of this entity
     *
     * @param relationColumns - an list of Columns objects
     */
    public void setRelationColumns(java.util.List<Columns> relationColumns) {
        this.relationColumns = relationColumns;
    }

    /**
     * This method gets the databaseColumnName attribute
     *
     * @return - an  java.lang.String  object
     */
    @Column(name = "DATABASE_COLUMN_NAME")
    public java.lang.String getDatabaseColumnName() {
        return this.databaseColumnName;
    }

    /**
     * The setter for DATABASE_COLUMN_NAME column
     *
     * @param databaseColumnName -  an  java.lang.String  object
     */
    public void setDatabaseColumnName(java.lang.String databaseColumnName) {
        this.databaseColumnName = databaseColumnName;
    }

    /**
     * This method gets the javaColumnName attribute
     *
     * @return - an  java.lang.String  object
     */
    @Column(name = "JAVA_COLUMN_NAME")
    public java.lang.String getJavaColumnName() {
        return this.javaColumnName;
    }

    /**
     * The setter for JAVA_COLUMN_NAME column
     *
     * @param javaColumnName -  an  java.lang.String  object
     */
    public void setJavaColumnName(java.lang.String javaColumnName) {
        this.javaColumnName = javaColumnName;
    }

    /**
     * This method gets the javaType attribute
     *
     * @return - an  java.lang.String  object
     */
    @Column(name = "JAVA_TYPE")
    public java.lang.String getJavaType() {
        return this.javaType;
    }

    /**
     * The setter for JAVA_TYPE column
     *
     * @param javaType -  an  java.lang.String  object
     */
    public void setJavaType(java.lang.String javaType) {
        this.javaType = javaType;
    }

    /**
     * This method gets the databaseType attribute
     *
     * @return - an  java.lang.String  object
     */
    @Column(name = "DATABASE_TYPE")
    public java.lang.String getDatabaseType() {
        return this.databaseType;
    }

    /**
     * The setter for DATABASE_TYPE column
     *
     * @param databaseType -  an  java.lang.String  object
     */
    public void setDatabaseType(java.lang.String databaseType) {
        this.databaseType = databaseType;
    }

    /**
     * This method gets the orderCol attribute
     *
     * @return - an  java.lang.Integer  object
     */
    @Column(name = "ORDER_COL")
    public java.lang.Integer getOrderCol() {
        return this.orderCol;
    }

    /**
     * The setter for ORDER_COL column
     *
     * @param orderCol -  an  java.lang.Integer  object
     */
    public void setOrderCol(java.lang.Integer orderCol) {
        this.orderCol = orderCol;
    }

    /**
     * This method gets the foreignKey attribute
     *
     * @return - an  java.lang.Integer  object
     */
    @Column(name = "FOREIGN_KEY")
    public java.lang.Integer getForeignKey() {
        return this.foreignKey;
    }

    /**
     * The setter for FOREIGN_KEY column
     *
     * @param foreignKey -  an  java.lang.Integer  object
     */
    public void setForeignKey(java.lang.Integer foreignKey) {
        this.foreignKey = foreignKey;
    }

    /**
     * This method gets the nullable attribute
     *
     * @return - an  java.lang.Integer  object
     */
    @Column(name = "NULLABLE")
    public java.lang.Integer getNullable() {
        return this.nullable;
    }

    /**
     * The setter for NULLABLE column
     *
     * @param nullable -  an  java.lang.Integer  object
     */
    public void setNullable(java.lang.Integer nullable) {
        this.nullable = nullable;
    }

    /**
     * This method maps an ManyToOne relation between this entity and
     * columns entity
     *
     * @return - an Columns object
     */
    @ManyToOne(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
    @JoinColumn(name = "FOREIGN_COLUMN", referencedColumnName = "ID")
    public Columns getForeignColumn() {
        return this.foreignColumn;
    }

    /**
     * This method sets the field foreignColumn of this entity
     *
     * @param foreignColumn - an Columns object
     */
    public void setForeignColumn(Columns foreignColumn) {
        this.foreignColumn = foreignColumn;
    }

    /**
     * This method gets the colSize attribute
     *
     * @return - an  java.lang.Integer  object
     */
    @Column(name = "COL_SIZE")
    public java.lang.Integer getColSize() {
        return this.colSize;
    }

    /**
     * The setter for COL_SIZE column
     *
     * @param colSize -  an  java.lang.Integer  object
     */
    public void setColSize(java.lang.Integer colSize) {
        this.colSize = colSize;
    }

    /**
     * This method maps an ManyToOne relation between this entity and
     * models entity
     *
     * @return - an Models object
     */
    @ManyToOne(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
    @JoinColumn(name = "OWNER_TABLE", referencedColumnName = "ID")
    public Models getOwnerTable() {
        return this.ownerTable;
    }

    /**
     * This method sets the field ownerTable of this entity
     *
     * @param ownerTable - an Models object
     */
    public void setOwnerTable(Models ownerTable) {
        this.ownerTable = ownerTable;
    }

    /**
     * This method maps an ManyToOne relation between this entity and
     * foreign_model entity
     *
     * @return - an ForeignModel object
     */
    @ManyToOne(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
    @JoinColumn(name = "FK_FOREIGN_MODEL", referencedColumnName = "ID")
    public ForeignModel getFkForeignModel() {
        return this.fkForeignModel;
    }

    /**
     * This method sets the field fkForeignModel of this entity
     *
     * @param fkForeignModel - an ForeignModel object
     */
    public void setFkForeignModel(ForeignModel fkForeignModel) {
        this.fkForeignModel = fkForeignModel;
    }

    @Override
    public boolean equals(Object obj) {

        if (obj == null || !(obj instanceof Columns))
            return false;
        Columns compared = (Columns) obj;
        return this.getDatabaseColumnName() != null &&
                compared.getDatabaseColumnName() != null &&
                this.getDatabaseColumnName().toLowerCase().trim().equals(
                        compared.getDatabaseColumnName().toLowerCase().trim()
                );

    }
}



